package com.sh.caryr.erp.entity.trade;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.sh.caryr.erp.entity.BaseEntity;
import lombok.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("erp_order")
public class Order extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    //*** System info
    private Integer orderType = 0;

    private Integer status;

    private int returnType = 0; //0.Not return; 1.Return usable; 2.Return broken

    /**
     * External platform. Eg.: JingDong; TianMao;
     */
    private String extPlatform;

    /**
     * External transaction Id
     */
    @Excel(name = "平台交易号", orderNum = "1", needMerge = true)
    private String extTxnId;

    @Excel(name = "店铺编号", isImportField = "true_st")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long shopId;

    //*** Receiver info
    @Excel(name = "收货人", isImportField = "true_st")
    private String receiver;

    @Excel(name = "昵称（旺旺号）", isImportField = "true_st")
    private String nickName;

    @Excel(name = "手机号码", isImportField = "true_st")
    private String phoneNum;

    @Excel(name = "固定电话")
    private String fixedPhoneNum;

    @Excel(name = "邮政编码")
    private String postCode;

    @Excel(name = "省", isImportField = "true_st")
    private String province;

    @Excel(name = "市", isImportField = "true_st")
    private String city;

    @Excel(name = "区", isImportField = "true_st")
    private String district;

    @Excel(name = "详细地址", isImportField = "true_st")
    private String address;

    @Excel(name = "买家备注")
    private String customRemark;

    //*** Logistics info
    private Integer logisticsType = 0;

    private String logisticsName;

    private String logisticsOrderId;

    private Integer isUrgent = 0;

    @Excel(name = "运费")
    private Float logisticsAmount;

    @Excel(name = "重量")
    private Float weight;

    //*** Payment info
    private Float orderAmount;

    @Excel(name = "总金额", isImportField = "true_st")
    private Float paymentAmount;

    private Float receiveAmount;

    //*** Invoice Info
    @Excel(name = "发票类型")
    private Integer invoiceType = 0;

    @Excel(name = "发票抬头")
    private String invoiceInfo;

    //*** Time info
    @Excel(name = "下单时间", format = "yyyy/MM/dd HH:mm")
    private Date orderTime;

    @Excel(name = "发货时间", format = "yyyy/MM/dd HH:mm")
    private Date deliveryTime;

    @Excel(name = "付款时间", format = "yyyy/MM/dd HH:mm")
    private Date paymentTime;


    @Excel(name = "系统备注")
    private String systemRemark;

    @TableField(exist = false)
    @ExcelCollection(name = "商品清单", orderNum = "4")
    private List<TradeOrder> tradeOrderList = new ArrayList<>();

    public void refreshOrderItem() {
        for (TradeOrder orderItem : getTradeOrderList()) {
            orderItem.setCoco(getCoco());
            orderItem.setTradeId(getId());
            orderItem.setUpdateAt(getUpdateAt());
            orderItem.setUpdateBy(getUpdateBy());
            orderItem.setStatus(getStatus());
        }
    }
}
